package com.multithreading.chart1.createMulitithreading;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @program: java-multithreading
 * @description: 使用FutureTask方式创建线程
 * @author: 陈庆彪
 * @create: 2020-06-20 09:44
 **/
public class FutureTest {
    public static void main(String[] args) throws InterruptedException {
        //创建异步任务
        FutureTask<String> futureTask=new FutureTask<>(new CallerTask());

        //启动线程
        new Thread(futureTask).start();

        //等待任务执行完毕，并返回结果
        try {
            String result=futureTask.get();
            System.out.println(result);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public static class CallerTask implements Callable<String>{

        @Override
        public String call() throws Exception {
            return "hello";
        }

    }


}
